package business;

import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import business.Foto;

/**
 *
 * @author Evangelista
 */
public class ASIFT extends Thread{
    
    @Override
    public void run(){
        
    }
    
    public static int exec_ASIFT_ext(BufferedImage panorama, String pano_id) throws InterruptedException {

        criaDiretorio();
        String params = buildParams(pano_id);
        System.out.println("--------- ASIFT_ENTRA");
        try {
            
            Runtime.getRuntime().exec("cmd /c prog_asift " + params).waitFor();
            System.out.println("Foi...");
            File arq = new File("temp/" + pano_id + "_matches.txt");
            FileReader file = new FileReader(arq);
            BufferedReader buf = new BufferedReader(file);
            
            System.out.println("--------- ASIFT_SAI");
            return Integer.parseInt(buf.readLine().split(" ")[0]);
        } catch (IOException ex) {
            System.out.println("TESTE");
            return -1;
        }
    }
    
        private static String buildParams(String pano_id) {
        //Panorama.salvarPano(panorama, "1.png");
        
        String retorno;
        
        retorno = "Panorama_" + pano_id + ".png"
                + " "
                + "foto_tirada.png"
                + " "
                + "temp/"+pano_id+"_comp1.png"
                + " "
                + "temp/"+pano_id+"_comp2.png"
                + " "
                + "temp/"+pano_id+"_matches.txt"
                + " "
                + "temp/"+pano_id+"_k1.txt"
                + " "
                + "temp/"+pano_id+"_k2.txt";
//                + " "
//                + "false";
                
        
         return retorno;
//        return "1.png foto_tirada.png 3.png 4.png m.txt k1.txt k2.txt";
    }
        
        private static void criaDiretorio(){
            File dir = new File("temp");
            dir.mkdir();
            
        }
    
}
